package com.yiqi.liebang.feature.setting.view;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.util.RxClipboardTool;
import com.yiqi.liebang.feature.order.PhoneDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AboutEnterActivity extends BaseActivity {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    RxPermissions rxPermissions;
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_about_enter;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        rxPermissions = new RxPermissions(this);
        initToolBar(mToolbar, "关于猎帮", true, true);
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.btn_mine_to_viefty, R.id.btn_mine_to_vieftyu})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_mine_to_viefty:
                RxClipboardTool.copyText(this,"liebangapp@126.com");
                T.showShort("已复制到剪贴板！");
                break;
            case R.id.btn_mine_to_vieftyu:
                PhoneDialog topicListDialog = new PhoneDialog(this, "0755-86906070");
                topicListDialog.show();
                topicListDialog.setDialClick(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        rxPermissions
                                .request(Manifest.permission.CALL_PHONE)
                                .subscribe(granted -> {
                                    if (granted) { // Always true pre-M
                                        diallPhone("0755-86906070");
                                        topicListDialog.dismiss();
                                    } else {
                                        showMsg("请先开启拨打电话权限!");
                                    }
                                });

                    }
                });
                break;
        }
    }

    /**
     * 拨打电话（跳转到拨号界面，用户手动点击拨打）
     *
     * @param phoneNum 电话号码
     */
    public void diallPhone(String phoneNum) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_CALL);
        //url:统一资源定位符
        //uri:统一资源标示符（更广）
        intent.setData(Uri.parse("tel:" + phoneNum));
        //开启系统拨号器
        startActivity(intent);
    }

}
